home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 06 interfaces and delegates / interfacesdemo / supportfunctions.vb < prev   
Encoding:
Text File  |  2001-07-28  |  1.7 KB  |  51 lines

  1. Module SupportFunctions
  2.     ' Raise to the 4th power.
  3.     Function Power4(ByRef x As Double) As Double
  4.         ' This is faster than x^4.
  5.         x = x * x
  6.         Power4 = x * x
  7.     End Function
  8.  
  9.     ' Two overloaded Sum functions
  10.     Overloads Function Sum(ByVal n1 As Long, ByVal n2 As Long) As Long
  11.         Sum = n1 + n2
  12.         Console.WriteLine("The integer version has been invoked.")
  13.     End Function
  14.  
  15.     Overloads Function Sum(ByVal n1 As Single, ByVal n2 As Single) As Single
  16.         Sum = n1 + n2
  17.         Console.WriteLine("The floating point version has been invoked.")
  18.     End Function
  19.  
  20.     ' Set an object to Nothing and clear its Dispose method if possible.
  21.     Sub ClearObject(ByRef obj As Object)
  22.         If TypeOf obj Is IDisposable Then
  23.             ' You need an explicit case if Option Strict is On.
  24.             CType(obj, IDisposable).Dispose()
  25.         End If
  26.         obj = Nothing
  27.     End Sub
  28.  
  29. End Module
  30.  
  31. ' This module is used to demonstrate that modules can raise events
  32.  
  33. Module FileOperations
  34.     Event Notify_CopyFile(ByVal source As String, ByVal destination As String)
  35.     Event Notify_DeleteFile(ByVal filename As String)
  36.  
  37.     Sub CopyFile(ByVal source As String, ByVal destination As String)
  38.         ' Perform the file copy.
  39.         System.IO.File.Copy(source, destination)
  40.         ' Notify that a copy occurred.
  41.         RaiseEvent Notify_CopyFile(source, destination)
  42.     End Sub
  43.  
  44.     Sub DeleteFile(ByVal filename As String)
  45.         ' Perform the file deletion.
  46.         System.IO.File.Delete(filename)
  47.         ' Notify that a deletion occurred.
  48.         RaiseEvent Notify_DeleteFile(filename)
  49.     End Sub
  50. End Module
  51.